﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;

public partial class cms_ListGallery : System.Web.UI.Page
{
    string path = "~/Images/Gallery/";
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["user"] == null)
        {
            Response.Redirect("Default.aspx");
        }
    }
    protected void GVGallery_RowCommand(object sender, GridViewCommandEventArgs e)
    {
        DBClass db = new DBClass();
        switch (e.CommandName)
        {
            case "Edit":
                Response.Redirect("AddNewGallery.aspx?Id=" + Convert.ToInt32(e.CommandArgument));
                break;
            case "Delete":
                string image = "";
                DataSet ds = db.GetAllGallery(Convert.ToInt32(e.CommandArgument));
                if (ds != null && ds.Tables.Count > 0 && ds.Tables[0].Rows.Count > 0)
                {
                    image = ds.Tables[0].Rows[0]["Image"].ToString();
                }
                if(System.IO.File.Exists(Server.MapPath(path+image)))
                {
                    System.IO.File.Delete(Server.MapPath(path + image));
                }
                db.DeleteGallery(Convert.ToInt32(e.CommandArgument));
                break;
            default:
                break;
        }
        Response.Redirect("ListGallery.aspx");
    }
}